//
//  GoldCoinPriceViewController.m
//  魔兽大数据
//
//  Created by 王右 on 2017/12/8.
//  Copyright © 2017年 王右. All rights reserved.
//

#import "GoldCoinPriceViewController.h"
#import "BigDataHeader.h"
#import "GoldCoinPriceTableViewCell.h"
#import "GoldCoinPirceModel.h"

@interface GoldCoinPriceViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *baseTableView;
@property (nonatomic, strong) NSMutableArray *modelArr;

@end

@implementation GoldCoinPriceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"金币价格";
    [RequestManager requestGetBigDataWithModule:@"goldsell/findAll" param:@{} model:@"GoldCoinPirceModel" success:^(NSArray *obj) {
        _modelArr = obj.mutableCopy;
        __block float total = 0;
        [_modelArr enumerateObjectsUsingBlock:^(GoldCoinPirceModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            total += obj.price.floatValue;
        }];
        
        [[CCCache defaultManager] setObject:@(total / _modelArr.count) forKey:@"serverGoldPriceAverage"];
        [_baseTableView reloadData];
    } failure:^(NSString *error) {
        
    }];
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _modelArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GoldCoinPriceTableViewCell *cell = (GoldCoinPriceTableViewCell *)[tableView cellWithCellNibName:@"GoldCoinPriceTableViewCell"];
    cell.model = _modelArr[indexPath.row];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
